package com.chinackts.customsdeclarations.query;

import com.alibaba.fastjson.JSONObject;
import com.chinackts.common.exception.ApplicationException;
import com.chinackts.common.validation.DateFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;

/**
 * @author Lianhong
 * @since 2021/11/18
 */
@ApiModel
public class CustomsDeclarationsListQuery {

    @ApiModelProperty("出口开始日期")
    @DateFormat(format = "yyyyMMdd", message = "出口开始日期格式错误，正确格式为yyyyMMdd")
    private String startDate;

    @ApiModelProperty("出口结束日期")
    @DateFormat(format = "yyyyMMdd", message = "出口结束日期格式错误，正确格式为yyyyMMdd")
    private String endDate;

    @ApiModelProperty("报关单号")
    private String entryId;

    @ApiModelProperty("报关单类型")
    private String decType;

    @ApiModelProperty("报关单列表加签")
    private String sign;

    @ApiModelProperty("启运港退税报关单采集标识")
    private boolean portOfDeparture = false;

    public String getStartDate() {
        return startDate;
    }

    public void setStartDate(String startDate) {
        this.startDate = startDate;
    }

    public String getEndDate() {
        return endDate;
    }

    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }

    public String getEntryId() {
        return entryId;
    }

    public void setEntryId(String entryId) {
        this.entryId = entryId;
    }

    public String getDecType() {
        return decType;
    }

    public void setDecType(String decType) {
        this.decType = decType;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public boolean isPortOfDeparture() {
        return portOfDeparture;
    }

    public void setPortOfDeparture(boolean portOfDeparture) {
        this.portOfDeparture = portOfDeparture;
    }

    public JSONObject buildQueries() {
        if (StringUtils.isAllBlank(startDate, endDate, entryId, decType)) {
            throw new ApplicationException("请提供查询参数");
        }
        JSONObject result = new JSONObject();
        result.put("decType", decType);
        if (StringUtils.isNotEmpty(entryId)) {
            result.put("entryId", entryId);
            result.put("startDate", StringUtils.EMPTY);
            result.put("endDate", StringUtils.EMPTY);
        } else {
            result.put("startDate", startDate);
            result.put("endDate", endDate);
        }
        return result;
    }

    /**
     * 结关报关单类型
     */
    public CustomsDeclarationsListQuery customsClearanceDecType() {
        this.decType = "1";
        return this;
    }

    /**
     * 起运港退税报关单类型
     */
    public CustomsDeclarationsListQuery portOfDepartureDecType() {
        this.decType = "2";
        return this;
    }

    /**
     * 退税联报关单类型
     */
    public CustomsDeclarationsListQuery taxRefundCopyDecType() {
        this.decType = "3";
        return this;
    }

}
